home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / NTOI.C < prev    next >
Text File  |  1993-06-26  |  512b  |  23 lines

  1. /*
  2.     this function converts ascii characters to an integer.
  3.     most common number bases may be used (except offset
  4.     octal).
  5. */
  6.  
  7. ntoi(n,b)
  8. char *n;
  9. int b;
  10. {
  11.     int val,sign;
  12.     char c;
  13.  
  14.     val=0; sign=1;
  15.     while ((c = *n) == '\t' || c == ' ') ++n;
  16.     if (c == '-') {sign = -1; n++;}
  17.     while (dig(c = *n++)) {
  18.        if (b == 16 && c >= 'A' && c <= 'F') c -= 7;
  19.        val = val * b + c - '0';
  20.     }
  21.     return sign*val;
  22. }
  23.